package net.aaa.hotel.dao.impl;

import net.aaa.hotel.dao.CustomDao;
import net.aaa.hotel.entity.Custom;
import net.aaa.hotel.util.BaseDB;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;
@Repository
public class CustomDaoImpl implements CustomDao {

    @Override
    public List<Map> fondCustom(Custom custom) {
        String sql = "select * from custom where iphone=? and pwd=?";
        return BaseDB.queryMap(sql,custom.getIphone(),custom.getPwd());
    }

    @Override
    public int addCustom(Custom custom) {
        String sql = "insert into custom (name,iphone,pwd,idcard)values(?,?,?,?)";
        return BaseDB.update(sql,custom.getName(),custom.getIphone(),custom.getPwd(),custom.getIdcard());
    }

    @Override
    public List<Map> queryAll(int l, int p,String condition) {
        String sql = "select * from custom where 1=1 ";
        if (condition!=null){
            sql+=condition;
        }
        sql+=" limit ?,?";
        int start = (p-1)*l;
        return BaseDB.queryMap(sql,start,l);
    }


    @Override
    public int cout(String condition) {
        String sql = "select count(*) a from  custom where 1=1";
        if (condition!=null){
            sql+=condition;
        }
        String a = BaseDB.queryMap(sql).get(0).get("a") + "";

        return  Integer.parseInt(a);
    }

    @Override
    public int gai(Integer id, Integer status) {
        String sql = "update  custom set status=? where id=?";
        return BaseDB.update(sql,status,id);
    }



}
